#include "qobjectface.h"

qobjectface::qobjectface(QObject *parent) : QObject(parent)
{
    //初始化 加载模型
       seeta::ModelSetting FDmode("D:/SeetaFace2/module/fd_2_00.dat",seeta::ModelSetting::CPU,0);//人脸检测模块
       seeta::ModelSetting PDmode("D:/SeetaFace2/module/pd_2_00_pts5.dat",seeta::ModelSetting::CPU,0);//面部特征5点   定位模块
       seeta::ModelSetting FRmode("D:/SeetaFace2/module/fr_2_10.dat",seeta::ModelSetting::CPU,0);// 人脸特征提取模块和比对模块
       this->ptr=new seeta::FaceEngine(FDmode,PDmode,FRmode);//通过该 指针来
      this->ptr->Load("./face.db");//加载人脸库


}

qobjectface::~qobjectface()
{
    delete ptr;
}

int64_t qobjectface::face_register(cv::Mat &faceimage)
{

   SeetaImageData simage;  //构造SeetaImageData 类型变量
   simage.data=faceimage.data;//将从客户端发来的图片数据来构建该类型变量 数据
   simage.width=faceimage.cols;// 宽
   simage.height=faceimage.rows;//高
   simage.channels=faceimage.channels();//通道
   int64_t faceid=this->ptr->Register(simage);// 底层注册函数需要一个SeetaImageData 类型变量

   if(faceid>=0)//说明人脸注册成功
   {

       ptr->Save("./face.db");//保存进人脸库
   }

    return faceid;
}

int qobjectface::face_query(cv::Mat &faceimage)
{
    SeetaImageData simage;// 同样构建该类型变量
    simage.data=faceimage.data;
    simage.width=faceimage.cols;
    simage.height=faceimage.rows;
    simage.channels=faceimage.channels();
    float similarity=0;
    int64_t faceid=ptr->Query(simage,&similarity);//在人脸库中查找该人脸
    if(similarity>0.65)//人脸辨识度
    {
        emit send_faceid(faceid); // 返回faceid信号
        qDebug()<<"人脸辨识度为："<<similarity<<"faceid为："<<faceid;

    }
    else
     {


        emit send_faceid(-1); // 返回faceid信号
        qDebug()<<"人脸辨识度为："<<similarity<<"faceid为："<<faceid;

    }
    return faceid;//有就会返回
}
